package com.leyantech.ecp.agenx.common.config;

import com.leyantech.ecp.agenx.common.utils.JsonUtils;
import com.leyantech.utility.config.ConfigUtil;

import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author eahau, {@literal <eahau@foxmail.com>}
 * @date 2022-11-24.
 */
public final class ConfigManager {

  private ConfigManager() {
  }

  public static final Supplier<List<String>> wholeLinkProductList = ConfigUtil.getDynamicConfig(
      "ecp_whole_link_product_list",
      json -> JsonUtils.fromJson(json, new TypeToken<List<String>>() {
      }),
      Lists.newArrayList()
  );

  public static final Supplier<Boolean> wholeLinkProductFuncEnabled = ConfigUtil.getDynamicConfig(
      "ecp_whole_link_product_func_enabled",
      Boolean::parseBoolean,
      Boolean.FALSE
  );

  public static final Supplier<List<String>> wholeLinkProductWhiteListStoreIdList = ConfigUtil
      .getDynamicConfig(
          "ecp_whole_link_product_whitelist_shops",
          json -> JsonUtils.fromJson(json, new TypeToken<List<String>>() {
          }),
          Lists.newArrayList()
      );

  public static final Supplier<Boolean> checkLxySeat = ConfigUtil.getDynamicConfig(
      "enable_check_lxk_seat",
      Boolean::parseBoolean,
      Boolean.FALSE
  );

  public static final Supplier<String> ASSISTANT_EVENT_TOPIC = ConfigUtil.getDynamicConfig(
      "1.ecp-agenx-pdd",
      "assistant-event.topic",
      Function.identity(),
      ""
  );

  public static final Supplier<String> DIALOGUE_TOPIC = ConfigUtil
      .getDynamicConfig("dialogue-all-in-one-topic", Function.identity(), "");

  public static final Supplier<Long> MESSAGE_EXPIRE_MILLS = ConfigUtil.getDynamicConfig(
      "expire.message.seconds",
      value -> TimeUnit.SECONDS.toMillis(Long.parseLong(value)),
      TimeUnit.SECONDS.toMillis(30L)
  );

  public static final Supplier<String> IMAGE_DOMAIN = ConfigUtil.getDynamicConfig(
      "pdd_image_domain",
      Function.identity(),
      "https://pddimages.ganjutech.com/"
  );

  public static final Supplier<Long> ITEMCARD_EXPIRE_MILLS = ConfigUtil.getDynamicConfig(
      "itemcard.expire.seconds",
      value -> TimeUnit.SECONDS.toMillis(Long.parseLong(value)),
      TimeUnit.SECONDS.toMillis(2)
  );

}
